import {
	wxlogin
} from "@/api/api/login.js"


export class Login {
	constructor(userInfo) {
		this.userInfo = userInfo
	}
	async go() {
		let data = await this.getCode()

		let {
			data: res
		} = await this.loginRequest(data)
		if (res.msg == "success") {
			uni.setStorageSync('login', res.datas)
			return res
		}

	}
	getCode() {
		return new Promise((resolve, reject) => {
			uni.login({
				provider: 'weixin',
				success: (loginRes) => {
					let data = {
						appid: 'wxdef49146de659da2',
						secret: '0666b8fefd2f8d08efc4ec02ce0c4887',
						nickName: this.userInfo.nickName,
						avatarUrl: this.userInfo.avatarUrl,
						code: loginRes.code,
					}
					// console.log(loginRes);
					// 	const {
					// 		data: res
					// 	} = await wxlogin(data)
					// 	if (res.msg === 'success') {
					// 		uni.setStorageSync('login', res.datas)
					// 		this.isLogin()
					// 	}

					resolve(data)

				}
			})
		})

	}
	loginRequest(data) {
		return wxlogin(data)
	}
}
